"use strict";
var require = require(["http://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.light.min.js"], function () {
    Geo.Map.App = function(app) {
        if (app == undefined) throw new Geo.Exception("application is undefined");
        if (document.getElementById('map') == undefined) throw new Geo.Exception("map is not defined");
        this.app = app;

        var apiKey = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
        this.map = new OpenLayers.Map('map');

        var road = new OpenLayers.Layer.Bing({
            key: apiKey,
            type: "Road",
            // custom metadata parameter to request the new map style - only useful
            // before May 1st, 2011
            metadataParams: { mapVersion: "v1" }
        });
        var aerial = new OpenLayers.Layer.Bing({
            key: apiKey,
            type: "Aerial"
        });
        var hybrid = new OpenLayers.Layer.Bing({
            key: apiKey,
            type: "AerialWithLabels",
            name: "Bing Aerial With Labels"
        });

        this.map.addLayers([road, aerial, hybrid]);
        this.map.addControl(new OpenLayers.Control.LayerSwitcher());

        var zoom = this.map.getZoomForResolution(76.43702827453613);

        this.map.setCenter(new OpenLayers.LonLat(-71.147, 42.472).transform(
            new OpenLayers.Projection("EPSG:4326"),
            this.map.getProjectionObject()
        ), zoom);
        
        this.app.SignalR.on('onPoint', function (result) {
            var layer = this.Map.getLayer(result.layerId);
            layer.redraw();
        });
        this.app.SignalR.invoke({ method: 'getLayers', success: function(result) {
            var layers = [];
            //result.forEach(function (item, index) {
            //    layers.push(new OpenLayers.Layer ()...)
            //});
        }});
    };
});